const express = require('express')
const app = express();
const path = require("path");
const fs = require("fs");
const multer = require('multer');

app.use(express.static(path.join(__dirname, './')));



const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, 'uploads/')
    },
    filename: function (req, file, cb) {
        //cb(null, file.fieldname + '-' + Date.now())
        cb(null, file.originalname);
    }
});

const upload = multer({ storage: storage });


app.all('*', function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    //Access-Control-Allow-Headers ,可根据浏览器的F12查看,把对应的粘贴在这里就行
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    res.header('Access-Control-Allow-Methods', '*');
    res.header('Content-Type', 'application/json;charset=utf-8');
    next();
});

app.get('/', function (req, res) {
    res.send("Hello");
})
app.post('/image/initScan', function (req, res) {
    res.json(require("./initview.json"));
});
app.get('/file/show', function (req, res) {
    // setTimeout(() => {
    //     res.redirect('/1.jpg');
    // }, 2000);
    res.redirect('/1.jpg');

});
app.get('/test/downloadfile', function (req, res) {
    //res.download('Chrome.zip');
    res.download('src.zip');
});
app.post('/file/fileupload', upload.any(), function (req, res) {
    console.log(req.files);
    let data = { "code": "200", "data": [{ "fileName": "55e9e774-e825-4a3b-9b7b-0ee129ab6497.jpg", "filePath": "e:/images/aip/2020/03/20/55e9e774-e825-4a3b-9b7b-0ee129ab6497.jpg", "fileDocumentName": "1584693768927" }, { "fileName": "f638066c-c23f-4965-bd33-c59d46d92ccb.jpg", "filePath": "e:/images/aip/2020/03/20/f638066c-c23f-4965-bd33-c59d46d92ccb.jpg", "fileDocumentName": "1584693774793" }], "message": "SUCCESS" };
    res.json(data);
});
app.post('/image/createImageDocument', function (req, res) {
    let data = { "code": "200", "data": { "downloadFirstUrl": "http://218.83.152.169:8074/DocumentManageServer/servlet/download", "downloadStandByUrl": "http://218.83.152.169:8074/DocumentManageServer/servlet/download", "docList": [{ "docIdInAthena": "E734B21D4663DE341CAE7049B3167AF1", "docIdOrigin": "88EB2E930F014508BE5A2ABCA583B380", "bizRefenceId": "3_3_2_5", "tag": "BLYW_TAG" }, { "docIdInAthena": "4DF9D4FD781A48D60B0C43AE82E8D57C", "docIdOrigin": "C0AFB4F9616A48EA8875E6817272484D", "bizRefenceId": "3_3_2_5", "tag": "BLYW_TAG" }], "fileList": [{ "docIdInAthena": "E734B21D4663DE341CAE7049B3167AF1", "fileId": "BDE35CA021B817340546EA25B692DB34", "fileName": "55e9e774-e825-4a3b-9b7b-0ee129ab6497.jpg" }, { "docIdInAthena": "4DF9D4FD781A48D60B0C43AE82E8D57C", "fileId": "263730C4F016FC822B72F98EED5AA9BE", "fileName": "f638066c-c23f-4965-bd33-c59d46d92ccb.jpg" }] }, "message": "SUCCESS" };
    res.json(data);
});

app.listen(3000);